﻿define([
    'Xjs/core/util',
    'Xjs/core/builder',
    'Xjs/ui/View'
],
function (util, builder, View) {
    'use strict';

    var type = 'menu',
    Menu = Xjs.getType(type);

    if (Menu) { // It has been already loaded
        return Menu;
    }

    Menu = util.define({
        base: View, // Must use view to avoid cyclic references
        construct: function (conf, parent) {

            Menu.base.constructor.call(this, conf, parent); // Call the base constructor

            this.handler = conf.handler;
        },
        requiresId: true,
        type: type,
        defaultChildType: 'menuItem',
        visible: false, // Initially invisible (not hidden)

        onRender: function () {

            var me = this;
            Menu.base.onRender.call(this);

            me.on('mouseout', function () {
                //me.setVisible(false);
            });
        },

        onUnhighlight: function () {

            var highlighted = false;

            this.down(function () {
                highlighted = highlighted || this.highlighted;
            });

            if (!highlighted) {
                this.setVisible(false);
            }
        }

    });

    Xjs.registerType(Menu);

    return Menu;
});